//
//  YYECourseBuyInfoTableViewCell.m
//  YuYingEDU
//
//  Created by 胡波 on 2018/1/19.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYECourseBuyInfoTableViewCell.h"

@interface YYECourseBuyInfoTableViewCell ()

@property (nonatomic,strong) UIImageView *courseIV;
@property (nonatomic,strong) UILabel *courseNameLabel;
@property (nonatomic,strong) UILabel *tipLabel;
@property (nonatomic,strong) UILabel *priceLabel;
@property (nonatomic,strong) UILabel *priceNumLabel;

@end

@implementation YYECourseBuyInfoTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.contentView.backgroundColor = GeneralBackColor;
        
        self.courseIV = [[UIImageView alloc]init];
        self.courseIV.layer.cornerRadius = 5;
        self.courseIV.clipsToBounds = YES;
        [self.contentView addSubview:self.courseIV];
        
        self.courseNameLabel = [[UILabel alloc]init];
        self.courseNameLabel.textColor = [UIColor blackColor];
        self.courseNameLabel.font = [UIFont systemFontOfSize:14];
        self.courseNameLabel.numberOfLines = 0;
        [self.contentView addSubview:self.courseNameLabel];
        
        self.tipLabel = [[UILabel alloc]init];
        self.tipLabel.textColor = LineColor;
        self.tipLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.tipLabel];
        
        self.priceLabel = [[UILabel alloc]init];
        self.priceLabel.textColor = [UIColor blackColor];
        self.priceLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.priceLabel];
        
        self.priceNumLabel = [[UILabel alloc]init];
        self.priceNumLabel.textColor = [UIColor redColor];
        self.priceNumLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.priceNumLabel];
        
//        self.courseIV.image = [UIImage imageNamed:@"courseHolder"];
//        self.courseNameLabel.text = @"Java基础入门阶段（javase教程，零基础java入门教程）";
//        self.tipLabel.text = @"购买后365天有效";
//        self.priceLabel.text = @"课程价格：";
//        self.priceNumLabel.text = @"￥299";
        
    }
    return self;
    
}

- (void)setModel:(YYECourseIntroModel *)model {
    _model = model;
    
    [self.courseIV sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"courseHolder"]];
    self.courseNameLabel.text = model.title;
    self.tipLabel.text = @"购买后365天有效";
    self.priceLabel.text = @"课程价格：";
    self.priceNumLabel.text = [NSString stringWithFormat:@"￥%@",model.price];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.courseIV makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(12);
        make.top.equalTo(self.contentView.top).offset(10);
        make.bottom.equalTo(self.contentView.bottom).offset(-10);
        make.size.equalTo(CGSizeMake(170, 94));
    }];
    
    
    [self.courseNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.courseIV.right).offset(6);
        make.top.equalTo(self.contentView.top).offset(16);
        make.right.equalTo(self.contentView.right).offset(-12);
    }];
    
    [self.tipLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.courseIV.right).offset(6);
        make.top.equalTo(self.courseNameLabel.bottom).offset(6);
    }];
    
    [self.priceLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.courseIV.right).offset(6);
        make.top.equalTo(self.tipLabel.bottom).offset(6);
    }];
    
    [self.priceNumLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.priceLabel.right);
        make.top.equalTo(self.priceLabel.top);
    }];
    

    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
